-
-
Notifications
You must be signed in to change notification settings - Fork 46.6k
Median of Two Arrays #3554
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Median of Two Arrays #3554
Conversation
This code finds the median of two arrays (which may or may not be sorted initially). Example: Enter elements of an array: 1 5 4 2 Enter elements of another array: 1 7 4 2 7 The median of two arrays is : 4
Travis tests have failedHey @anneCoder1805, TravisBuddy Request Identifier: a6753050-1200-11eb-af4f-e3a6e0ba4ce0 |
Travis tests have failedHey @anneCoder1805, TravisBuddy Request Identifier: 08572c10-1201-11eb-af4f-e3a6e0ba4ce0 |
Travis tests have failedHey @anneCoder1805, TravisBuddy Request Identifier: 2f17a1b0-129f-11eb-af4f-e3a6e0ba4ce0 |
Please reformat this code with psf/black as discussed in CONTRIBUTING.md so that the tests below turn green. |
other/median_of_two_arrays.py
Outdated
m = findMedianArrays(n1, n2) | ||
print(f'The median of two arrays is: {m}') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
m = findMedianArrays(n1, n2) | |
print(f'The median of two arrays is: {m}') | |
print(f'The median of two arrays is: {findMedianArrays(n1, n2)}') |
@cclauss , thanks for letting me know. I will format the the code accordingly :) |
Travis tests have failedHey @anneCoder1805, TravisBuddy Request Identifier: 4613a080-12a4-11eb-8230-47bfa5f272e1 |
Travis tests have failedHey @anneCoder1805, TravisBuddy Request Identifier: 8f00cbf0-12a5-11eb-8230-47bfa5f272e1 |
other/median_of_two_arrays.py
Outdated
list3 = nums1 + nums2 | ||
list3 = nums1 + nums2 | ||
list3.sort() | ||
if divmod(len(list3), 2).[1] == 1: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if divmod(len(list3), 2).[1] == 1: | |
div, mod = divmod(len(list3), 2) | |
if mod == 1: |
Then replace a
with div
which is already calculated.
other/median_of_two_arrays.py
Outdated
list3 = nums1 + nums2 | ||
list3 = nums1 + nums2 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
list3 = nums1 + nums2 | |
list3 = nums1 + nums2 | |
all_numbers = nums1 + nums2 |
Remove duplication and use a more self-documenting variable name.
other/median_of_two_arrays.py
Outdated
all_numbers = nums1 + nums2 | ||
all_numbers.sort() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
all_numbers = nums1 + nums2 | |
all_numbers.sort() | |
all_numbers = sorted(nums1 + nums2) |
@cclauss |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome work! Thanks for your persistence.
* Create medianOf TwoArrays.py This code finds the median of two arrays (which may or may not be sorted initially). Example: Enter elements of an array: 1 5 4 2 Enter elements of another array: 1 7 4 2 7 The median of two arrays is : 4 * Rename medianOf TwoArrays.py to median_of _two_arrays.py * Rename median_of _two_arrays.py to median_of_two_arrays.py * Update median_of_two_arrays.py * Update median_of_two_arrays.py * Update median_of_two_arrays.py * Update median_of_two_arrays.py * Update median_of_two_arrays.py * Update median_of_two_arrays.py * Update median_of_two_arrays.py * Update median_of_two_arrays.py * Update median_of_two_arrays.py * Update median_of_two_arrays.py * Update median_of_two_arrays.py * Update median_of_two_arrays.py * Update median_of_two_arrays.py * Update median_of_two_arrays.py * Update median_of_two_arrays.py * Update median_of_two_arrays.py * Update median_of_two_arrays.py
* Create medianOf TwoArrays.py This code finds the median of two arrays (which may or may not be sorted initially). Example: Enter elements of an array: 1 5 4 2 Enter elements of another array: 1 7 4 2 7 The median of two arrays is : 4 * Rename medianOf TwoArrays.py to median_of _two_arrays.py * Rename median_of _two_arrays.py to median_of_two_arrays.py * Update median_of_two_arrays.py * Update median_of_two_arrays.py * Update median_of_two_arrays.py * Update median_of_two_arrays.py * Update median_of_two_arrays.py * Update median_of_two_arrays.py * Update median_of_two_arrays.py * Update median_of_two_arrays.py * Update median_of_two_arrays.py * Update median_of_two_arrays.py * Update median_of_two_arrays.py * Update median_of_two_arrays.py * Update median_of_two_arrays.py * Update median_of_two_arrays.py * Update median_of_two_arrays.py * Update median_of_two_arrays.py * Update median_of_two_arrays.py
* Create medianOf TwoArrays.py This code finds the median of two arrays (which may or may not be sorted initially). Example: Enter elements of an array: 1 5 4 2 Enter elements of another array: 1 7 4 2 7 The median of two arrays is : 4 * Rename medianOf TwoArrays.py to median_of _two_arrays.py * Rename median_of _two_arrays.py to median_of_two_arrays.py * Update median_of_two_arrays.py * Update median_of_two_arrays.py * Update median_of_two_arrays.py * Update median_of_two_arrays.py * Update median_of_two_arrays.py * Update median_of_two_arrays.py * Update median_of_two_arrays.py * Update median_of_two_arrays.py * Update median_of_two_arrays.py * Update median_of_two_arrays.py * Update median_of_two_arrays.py * Update median_of_two_arrays.py * Update median_of_two_arrays.py * Update median_of_two_arrays.py * Update median_of_two_arrays.py * Update median_of_two_arrays.py * Update median_of_two_arrays.py
* Create medianOf TwoArrays.py This code finds the median of two arrays (which may or may not be sorted initially). Example: Enter elements of an array: 1 5 4 2 Enter elements of another array: 1 7 4 2 7 The median of two arrays is : 4 * Rename medianOf TwoArrays.py to median_of _two_arrays.py * Rename median_of _two_arrays.py to median_of_two_arrays.py * Update median_of_two_arrays.py * Update median_of_two_arrays.py * Update median_of_two_arrays.py * Update median_of_two_arrays.py * Update median_of_two_arrays.py * Update median_of_two_arrays.py * Update median_of_two_arrays.py * Update median_of_two_arrays.py * Update median_of_two_arrays.py * Update median_of_two_arrays.py * Update median_of_two_arrays.py * Update median_of_two_arrays.py * Update median_of_two_arrays.py * Update median_of_two_arrays.py * Update median_of_two_arrays.py * Update median_of_two_arrays.py * Update median_of_two_arrays.py
This code finds the median of two arrays (which may or may not be sorted initially).
Example:
Enter elements of an array: 1 5 4 2
Enter elements of another array: 1 7 4 2 7
The median of two arrays is : 4
Describe your change:
Checklist:
Fixes: #{$ISSUE_NO}
.